package edu.tjpu.share.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import edu.tjpu.share.service.NetworkStateService;

public class ConnectionChangeReceiver extends BroadcastReceiver {
	 public static String TIME_CHANGED_ACTION = "org.catalyst.service.action.TIME_CHANGED_ACTION";
	@Override
	public void onReceive(Context context, Intent intent) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
		NetworkInfo mobNetInfo = connectivityManager
				.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		if (activeNetInfo!=null&&activeNetInfo.getType()==ConnectivityManager.TYPE_WIFI&&mobNetInfo!=null&&(mobNetInfo.getState() == State.DISCONNECTED||mobNetInfo.getState() == State.DISCONNECTING)) {
				Intent intent2 = new Intent();
				intent2.putExtra("TypeName", activeNetInfo.getTypeName());
				intent2.setAction(NetworkStateService.SYNC_ACTION);
				intent2.setClass(context, NetworkStateService.class);
				context.startService(intent2);
		}
	}
}